﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Waker.Common;

namespace Waker.Records
{
    public partial class FormNormalRecord : Base.FormBaseToolBar
    {
        public FormNormalRecord()
        {
            InitializeComponent();
        }
        private void FormNormalRecord_Load(object sender, EventArgs e)
        {
            //dteBeginDate.DateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            //dteEndDate.DateTime = dteBeginDate.DateTime.AddMonths(1).AddSeconds(-1);
            dteBeginDate.DateTime = DateTime.Parse(DateTime.Now.ToShortDateString());
            dteEndDate.DateTime = DateTime.Parse(DateTime.Now.ToShortDateString()).AddDays(1).AddSeconds(-1);
            var dtSite = new BAL.BAL_Cards().GetAllDepartment();
            ckbListSubContractor.Properties.DataSource = dtSite;
            FormRefresh();
        }
        public override void FormRefresh()
        {
            try
            {
                StartWaiting();
                DateTime endDate = DateTime.Parse(dteEndDate.DateTime.ToShortDateString()).AddDays(1).AddSeconds(-1);
                var dt = new BAL.BAL_Records().WipeRecordSeach(
                  dteBeginDate.DateTime
                    , endDate
                    , ckbListSubContractor.EditValue == null ? string.Empty : ckbListSubContractor.EditValue.ToString().Trim()
                    , txtEmp_Name.Text.Trim()
                    , txtEmp_No.Text.Trim()
                    , txtEmp_IDCard.Text.Trim()
                    , false
                    );
                this.gridControl1.DataSource = dt;
                if (gridView1.GroupCount > 0)
                    gridView1.ExpandGroupRow(gridView1.FocusedRowHandle, false);
            }
            catch (Exception ex)
            {
                UI.ShowError(ex.Message);
            }
            finally
            {
                EndWaiting();
            }
        }
        private void btnSearch_Click(object sender, EventArgs e)
        {
            FormRefresh();
        }

        private void repositoryItemButtonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            try
            {
                StartWaiting();
                if (gridView1.FocusedRowHandle < 0)
                    return;
                var dr = this.gridView1.GetFocusedDataRow();
                if (dr == null || dr["Event_Pic"] == DBNull.Value || string.IsNullOrEmpty(dr["Event_Pic"].ToString()))
                    return;
                System.Diagnostics.Process process = new System.Diagnostics.Process();
                process.StartInfo.FileName = dr["Event_Pic"].ToString();
                process.StartInfo.Verb = "Open";
                process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
                process.Start();
            }
            catch (Exception ex)
            {
                UI.ShowError(ex.Message);
            }
            finally
            {
                EndWaiting();
            }
        }
    }
}
